
"""1.新建名片"""


def new_business():
    name = input("输入姓名：")
    age = input("输入年龄：")
    phone = input("请输入手机号：")
    email = input("请输入您邮箱：")
    new_dict = {"name": name,
                "age": age,
                "phone": phone,
                "email": email
                }
    list_user.append(new_dict)
    print("您添加了用户{0}".format(name))


"""2.显示全部"""


def show():
    if list_user == []:
        print("用户名片为空，请添加名片后查询")
        return
    print("姓名\t", end="     ")
    print("年龄\t", end="     ")
    print("手机\t", end="        ")
    print("邮箱\t")
    for f in list_user:
        for n in f.values():
            print(n, "\t", end=" ")
        print("")
    print("*"*60)
    print("您需要以下哪种操作:1.增加名片   2.修改名片  3.删除名片   4.清空用户   0.返回")
    num = input("请输入您的要的操作：")
    # 新增名片
    if num == "1":
        new_business()
        return
    # 修改名片
    if num == "2":
        name = input("请输入您要修改的用户:")
        for f in list_user:
            if name in f.values():
                list_user.remove(f)
                print("请重新输入{0}的信息！".format(name))
                new_business()
                return
        print("用户不存在！")
    # 删除名片
    if num == "3":
        name = input("请输入您要删除的用户:")
        for f in list_user:
            if name in f.values():
                list_user.remove(f)
                print("已经将用户{0}删除".format(name))
                return
        print("用户不存在！")
    # 清空用户列表
    if num == "4":
        list_user.clear()
        print("用户名片已经清空了！")
        return
    # 返回
    if num == "0":
        return


"""查询名片"""


def inquire():
    if list_user == []:
        print("用户名片为空，请添加名片后查询")
    name = input("请输入您要查询的用户名称:")
    for f in list_user:
        if name in f.values():
            print("姓名\t", end="     ")
            print("年龄\t", end="     ")
            print("手机\t", end="        ")
            print("邮箱\t")
            for n in f.values():
                print(n, "\t", end=" ")
            return
    else:
        print("用户不存在！")


"""主体函数"""


def business():
    print("欢迎使用名片管理系统v1.0")
    while True:
        print("-" * 60, "\n1.新建名片\n2.显示全部\n3.查询名片\n\n0.退出系统\n", "-" * 60)
        action = input("请输入您的选择操作：")
        li = ("1", "2", "3", "0")
        if action not in li:
            print("输入数据只能是(1，2，3，0),请重新输入")
            return
        print("您选择的操作是{0}".format(action))
        print("-" * 60)
        if action == "1":
            new_business()
        if action == "2":
            show()
        if action == "3":
            inquire()
        if action == "0":
            print("您已退出系统,欢迎下次使用!")
            break


# 设置初始化数据
list_user = [{"name": "小明", "age": 11, "phone": 18727929920, "email": 25525252525},
             {"name": "小红", "age": 22, "phone": 18727929921, "email": 25525252526},
             {"name": "小亮", "age": 33, "phone": 18727929922, "email": 25525252527}]
business()